package org.example
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.desc
import org.apache.spark.sql.types.{IntegerType, StringType, StructField, StructType}

object class0508 {
  //词频统计
  def main(args: Array[String]): Unit = {
    val sparkConf = new
        SparkConf().setMaster("local[2]").setAppName("NetworkWordCount")
    val ssc = new StreamingContext(sparkConf, Seconds(5))
    val dStream: ReceiverInputDStream[String] =
      ssc.socketTextStream("localhost",9999)
    val lines: DStream[String] = dStream.flatMap(_.split(" "))
    val wordDStream: DStream[(String,Int)] = lines.map((_,1))
    val result = wordDStream.reduceByKey(_+_)
    result.print()
    ssc.start()
    ssc.awaitTermination()

  }

}
